package com.sphd.restaurantsystem.model;


import com.android.volley.VolleyError;
import com.sphd.restaurantsystem.info.InvestRuleInfo;
import com.sphd.restaurantsystem.info.InvestorInfo;
import com.sphd.restaurantsystem.interfaces.VolleyJsonObjectCallBack;
import com.sphd.restaurantsystem.presenter.FundingPresenter;
import com.wzh.frame.utils.JsonUtil;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

/**
 * Created by Hu on 2016/11/03
 */

public class FundingModelImpl implements FundingModel, VolleyJsonObjectCallBack {
    FundingPresenter fundingPresenter;

    @Override
    public void sendUrl(String url, FundingPresenter fundingPresenter) {
        this.fundingPresenter = fundingPresenter;
        volleyUtil.setJsonObjectRequest(url, this);
    }

    @Override
    public void onResponse(JSONObject response) {
        try {
            List<InvestorInfo> investorInfos = JsonUtil.getListFromString(response.getString("list"), InvestorInfo.class);
            List<InvestRuleInfo> investRuleInfos = JsonUtil.getListFromString(response.getString("listrule"), InvestRuleInfo.class);
            int status = response.getInt("status");
            int repeal_apply = response.getInt("repeal_apply");
            int import_apply = response.getInt("import_apply");
            double sum = response.getDouble("sum");
            fundingPresenter.sendRes(investorInfos,investRuleInfos,status,repeal_apply,import_apply,sum);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onErrorResponse(VolleyError error) {
fundingPresenter.sendError(error);
    }
}